package com.example.larouzey.fragmenttest201ljy.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.larouzey.fragmenttest201ljy.R;
import com.example.larouzey.fragmenttest201ljy.adapter.ArticleMyAdapter;
import com.example.larouzey.fragmenttest201ljy.bean.ArticleBean;
import com.example.larouzey.fragmenttest201ljy.iface.ArticleListener;

import java.util.List;

/**
 * Created by Neusoft on 2017/4/9.
 */

public class Fragment2 extends Fragment {
    private RecyclerView rv;//RecyclerView 控件
    private RecyclerView.LayoutManager lm;//RecyclerView控件布局
    private ArticleMyAdapter ma;//RecyclerView
    private List<ArticleBean> list = null;

    ArticleListener articleListener=new ArticleListener() {
        @Override
        public void onResponse(List<ArticleBean> beanList) {
            list=beanList;//获取文章
            ma.setList(list);
            ma.notifyDataSetChanged();//通知更新
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getActivity(),"失败："+msg,Toast.LENGTH_SHORT);
        }
    };

    private  TextView tvinfo;
    private View view=null;
    private Context context;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context=getActivity();
       //动态加载Fragment1的布局文件
        view=inflater.inflate(R.layout.fragment2,container,false);
        //获取布局上的控件，注意通过view获取
        tvinfo=(TextView)view.findViewById(R.id.textView222);
        tvinfo.setText("朋友");
        //注意Toast第一个参数上下文
        Toast.makeText(context, "加载Fragmen2朋友", Toast.LENGTH_SHORT).show();
        //返回动态生成的view
        return view;
    }
}
